'use strict';

const db = uniCloud.database();
let response = function(code, data, msg) {
	return {
		code: code,
		data: data,
		msg: msg || '成功'
	}
};

exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	if (event.api == 'errlogUpload') {
		return errlogUpload(event)
	}
	//返回数据给客户端 结果
	return event
};

/**
 * 意见收集
 * @param {String}  authorId 创建者 
 * @param {String}  content  内容
 * */
var errlogUpload = async (param) => {
	if (!param.phone)
		return response(20000, undefined, '参数错误')
	let collection = await db.collection('cctvJfscErrLog');
	let result = await collection.add({
		memberId: param.memberId,
		nickName: param.nickName,
		phone: param.phone,
		url: param.url,
		apiParam: param.apiParam,
		apiResult: param.apiResult,
		createTime: param.createTime,
		createTimeStr: param.createTimeStr
	})
	return response(10000, result.data)
};
